﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace emlak
{
    public partial class frmArzArama : Form
    {
        public frmArzArama()
        {
            InitializeComponent();
        }

        

        private void btnArama_Click(object sender, EventArgs e)
        {
            if (rdbilanID.Checked == true)
            {

                if (rdbArsaArazi.Checked == true)
                    dgArzArama.DataSource = Sorgu.ArsaArzGetir_ID(Convert.ToInt32(txtIlanId.Text));
                else if (rdbEvKooperatif.Checked == true)
                    dgArzArama.DataSource = Sorgu.EvArzGetir_ID(Convert.ToInt32(txtIlanId.Text));
                else if (rdbIsYeriBuro.Checked == true)
                    dgArzArama.DataSource = Sorgu.IsyeriArzGetir_ID(Convert.ToInt32(txtIlanId.Text));
                else MessageBox.Show("Hatalı seçim");
            }

            

            /*
            try
            {
                SqlConnection cnn = new SqlConnection("Data Source=UURYSR-PC;Initial Catalog=projeiçi;Integrated Security=True");
                cnn.Open();
                DataTable dt = new DataTable();
                SqlDataAdapter da = new SqlDataAdapter("select * from projeiçi.dbo.EvArz", cnn);

                da.Fill(dt);
                dataGridView1.DataSource = dt;
                cnn.Close();
                MessageBox.Show("işlem tamam");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
             */
          //  ArzAramaAtama();
        }

        public void ArzAramaAtama() {

            snfArzArama ArzArama = new snfArzArama();

            ArzArama.Ilanid =Convert.ToInt32(txtIlanId.Text);
            ArzArama.Ad = txtAdi.Text;
            ArzArama.Soyad = txtSoyadi.Text;
            //ArzArama.Koopad = txtKooperatifAdi.Text;
            ArzArama.Il = Convert.ToString(cmbIl.SelectedItem);
            ArzArama.Ilce = Convert.ToString(cmbIlce.SelectedItem);
            ArzArama.Semt = Convert.ToString(cmbSemt.SelectedItem);
           // ArzArama.Islemgörmedurum = cmbIslemDurumu.SelectedIndex;
            ArzArama.Minfiyat = Convert.ToDouble(txbEnAzFiyat.Text);
            ArzArama.Maxfiyat = Convert.ToDouble(txbEnYuksekFiyat.Text);
           
            //Radio Button Kontrolleri..

            //Gayrimenkul Tipine Gore..
            //ev-kooperatifse 1, İs Yeri Buro İse 2, Arsa Araziyse 3, Tumu ise 4
            if (rdbkontrol(rdbEvKooperatif) == 1) 
                ArzArama.Gayrimenkultip = 1;
            else if (rdbkontrol(rdbIsYeriBuro) == 1)
                ArzArama.Gayrimenkultip = 2;
            else if (rdbkontrol(rdbArsaArazi) == 1)
                ArzArama.Gayrimenkultip = 3;
            else if (rdbkontrol(rdbTumu) == 1)
                ArzArama.Gayrimenkultip = 4;
            //İslem Tipine Göre..
            //Kiralık ise 1, Satilik ise 2, Tümü ise 3 değerini alacak;
            if (rdbkontrol(rdbKiralik) == 1)
                ArzArama.Gayrimenkultip = 1;
            else if (rdbkontrol(rdbSatilik) == 1)
                ArzArama.Gayrimenkultip = 2;
            else if (rdbkontrol(rdbTumu) == 1)
                ArzArama.Gayrimenkultip = 3;
        }

        public int rdbkontrol(RadioButton a) 
        {
            if (a.Checked == true) 
                return 1;
            else 
                return 0;

        }

        public void rakamkontrol(KeyPressEventArgs e)
        {


            if ((int)e.KeyChar >= 47 && (int)e.KeyChar <= 58)
            {

                e.Handled = false;//Basilan tusu yaz

            }

            else if ((int)e.KeyChar == 8)
            {

                e.Handled = false;//Basilan tusu yaz

            }

            else
            {

                e.Handled = true;//Basilan tusu yoksay ve yazma
            }
        }

        private void txtIlanId_KeyPress(object sender, KeyPressEventArgs e)
        {
            rakamkontrol(e);
        }

        private void txbEnAzFiyat_KeyPress(object sender, KeyPressEventArgs e)
        {
            rakamkontrol(e);
        }

        private void txbEnYuksekFiyat_KeyPress(object sender, KeyPressEventArgs e)
        {
            rakamkontrol(e);
        }


    }
}
